home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic 4 Database How-To
/
Visual Basic 4 Database - How-to (The Waite Group)(1995).iso
/
vendor.cl_
/
vendor.cl
Wrap
Text File
|
1994-11-20
|
7KB
|
245 lines
Version 1.0 Class
Attribute VB_Name = "clsVendor"
Attribute VB_Creatable = True
Attribute VB_Exposed = False
Option Explicit
' Vendor number is an integer. It must be a positive integer (negative
' numbers would make no sense. These constants define the legal limits
' of a positive integer.
Const MIN_VENDORNUMBER = 1
Const MAX_VENDORNUMBER = 32767
' These are the private variables used to hold the object properties.
' Each is readable by outside routines via Property Get routines but is
' not directly modifiable by outside routines.
Private propNumber As Integer
Private propCompany As String
Private propAddress As String
Private propFEIN As String
' The propDelimitedString variable is not readable by outside routines but
' can be set by a Property Let statement.
Private propDelimitedString As String
'*****************************************************************************
Property Let DelimitedString(delim As String)
' Stores the passed argument as the DelimitedString property
' Each string represents one record. This routine parses
' the string into fields and stores the field values as the
' appropriate object properties.
Dim delimiter As String
Dim endPos As Integer, fieldNum As Integer, startPos As Integer
Dim i As Integer
Dim textNumber As String
' Define the string used to delimit fields within a record.
delimiter = Chr$(9)
' Store the argument as a property.
propDelimitedString = delim
' Initialize the parse routine.
startPos = 1
fieldNum = 1
' Go through the string. Extract each field. Stop when the maximum
' number of fields is reached or the string ends. (If the input data
' is correct, the string should never end before the maximum number
' of fields is reached.)
Do
' Find the position of the delimiter character in the string,
' starting from the character after the last delimiter found.
endPos = InStr(startPos, delim, delimiter)
' If we didn't find one, set the position to the end of the string.
If endPos = 0 Then endPos = Len(delim) + 1
' Process the field that the text between startPos and endPos
' represents.
Select Case fieldNum
Case 1
' Extract the text enclosed by startPos and endPos.
textNumber = ExtractField(startPos, endPos)
' Check to make sure this text represents a legal Vendor
' Number. If it doesn't. set the value of the vendor number
' to zero. This allows the remainder of the record to be
' processed. Outside routines can use Property Get Number
' to check to make sure the vendor number is non-zero.
If IsNumeric(textNumber) Then
If textNumber >= MIN_VENDORNUMBER And textNumber _
<= MAX_VENDORNUMBER Then
propNumber = Val(textNumber)
Else
propNumber = 0
End If
Else
propNumber = 0
End If
Case 2
propCompany = ExtractField(startPos, endPos)
Case 3
propAddress = ExtractField(startPos, endPos)
Case 4
propFEIN = ExtractField(startPos, endPos)
End Select
' Set the startPos for the next cycle to the character past the
' existing endPos.
startPos = endPos + 1
' Increment the fieldNum loop control variable.
fieldNum = fieldNum + 1
' If we're not at the end of the string or the end of the field list,
' keep going.
Loop While endPos < Len(delim) And fieldNum <= 4
End Property
'*****************************************************************************
Public Function StoreNewItem(rs As Recordset) As Boolean
' Saves the value of the object as a new record in the recordset passed
' as the argument. Returns True if it succeeds, False if an error occurs.
On Error GoTo StoreNewError
' Prepare to add a new record.
rs.AddNew
' Call WriteItem to update the values. If WriteItem, it encountered no
' errors, so go ahead and save the record. It WriteItem returns False,
' there was an error, so go to the error handler.
If WriteItem(rs) Then
rs.Update
Else
GoTo StoreNewError
End If
' Set the return value to indicate success.
StoreNewItem = True
Exit Function
StoreNewError:
' Set the return value to indicate an error and return to the calling
' routine.
StoreNewItem = False
Exit Function
End Function
'*****************************************************************************
Private Function WriteItem(rs As Recordset) As Boolean
' Assigns the current property values to the Vendor table fields in
' the current record. Returns True unless an error is encountered.
' Set up the error handler.
On Error GoTo WriteItemError
' Assign property values to table fields.
rs("Vendor Number") = propNumber
rs("Name") = propCompany
rs("Address") = propAddress
rs("FEIN") = propFEIN
' Return True to indicate no errors.
WriteItem = True
Exit Function
WriteItemError:
' Return False to indicate an error.
WriteItem = False
Exit Function
End Function
'*****************************************************************************
Private Function ExtractField(startPos As Integer, endPos As Integer)
' Returns the text from propDelimitedString between the startPos and
' endPos positions.
ExtractField = Mid$(propDelimitedString, startPos, (endPos - startPos))
End Function
'*****************************************************************************
Property Get Number() As Integer
' Returns the current value of propVendorNumber
Number = propNumber
End Property
'*****************************************************************************
Property Get Company() As String
' Returns the current value of propCompany.
Company = propCompany
End Property
'*****************************************************************************
Property Get Address() As String
' Returns the current value of propAddress.
Address = propAddress
End Property
'*****************************************************************************
Property Get FEIN() As String
' Returns the current value of propFEIN
FEIN = propFEIN
End Property